import requests
import json
from common.yaml_util import YamlUtil
 
class RequestUtil:
 
    def __init__(self,two_node):
        self.base_url=YamlUtil().read_config('base',two_node)
 
    sess= requests.session()
 
    def send_request(self,method,url,datas=None,**kwargs):
        method=str(method).lower()  #转换小写
        url=self.base_url + url
        res=None
        if method=="get":
            res=RequestUtil.sess.request(method=method,url=url,params=datas,**kwargs)
        elif method=="post":
            if datas and isinstance(datas,dict):
                datas=json.dumps(datas)
            res=RequestUtil.sess.request(method=method, url=url, data=datas, **kwargs)
        else:
            pass
        return res